<template>
    <div class="content">
        <div class="btns-box">
            <Button type="primary" @click="saveAdd">暂存</Button>
            <Button type="primary" v-if="form.id" :disabled="this.form.status===''" @click="delAll">删除</Button>
            <div class="f-fr">
                <Button type="primary" @click="submitAll">申报</Button>
            </div>
        </div>
        <div class="base-info">
            <h3>基本数据</h3>
        </div>
        <div class="content-body">
            <Form
                :model="form"
                :rules="formRules"
                :data-current="currentIndex"
                class="declare-form"
                ref="form"
                :show-message="false"
            >
                <!-- 第1行 -->
                <Row>
                    <Col class="form-label label-border" span="4">申请编号</Col>
                    <Col span="4">
                    <FormItem prop="applyId" class="formInput">
                        <Input disabled v-model="form.applyId" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="4">商务部申请表号</Col>
                    <Col span="4">
                    <FormItem prop="commerceApplyId" class="formInput">
                        <Input disabled placeholder="申报后自动生成" v-model="form.commerceApplyId" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="4">许可证号</Col>
                    <Col span="4">
                    <FormItem prop="licenceKey" class="formInput">
                        <Input disabled v-model="form.licenceKey" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第2行 -->
                <Row>
                    <Col class="form-label label-border" span="4">年度</Col>
                    <Col span="4">
                    <FormItem prop="year" class="formInput requireBG">
                        <Select v-model="form.year" class="small-select">
                            <Option value="2020">2020</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="4">状态</Col>
                    <Col span="4">
                    <FormItem prop="status" class="formInput requireBG">
                        <Input disabled v-model="form.status" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">报关口岸</Col>
                    <Col span="4">
                    <FormItem prop="customsPort" class="formInput requireBG">
                        <Select v-model="form.customsPort" class="small-select">
                            <Option
                                :value="item.dataCode"
                                v-for="item in customsCodeList"
                                :key="item.dataCode"
                            >{{item.dataCode}}-{{item.dataName}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第3行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">出口商代码</Col>
                    <Col span="4">
                    <FormItem prop="exporterCode" class="formInput">
                        <Input disabled v-model="form.exporterCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="4">出口商社会信用代码</Col>
                    <Col span="4">
                    <FormItem prop="exporterSocialCode" class="formInput">
                        <Input disabled v-model="form.exporterSocialCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">出口商名称</Col>
                    <Col span="4">
                    <FormItem prop="exporterName" class="formInput">
                        <Input disabled v-model="form.exporterName" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第4行 -->
                <Row>
                    <Col class="form-label label-border" span="4">发货人代码</Col>
                    <Col span="4">
                    <FormItem prop="shipperCode" class="formInput requireBG">
                        <Input v-model="form.shipperCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-top" span="4">发货人社会信用代码</Col>
                    <Col span="4">
                    <FormItem prop="shipperSocialCode" class="formInput requireBG">
                        <Input disabled v-model="form.shipperSocialCode" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">发货人名称</Col>

                    <Col span="4">
                    <FormItem prop="shipperName" class="formInput requireBG">
                        <Input v-model="form.shipperName" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第5行 -->
                <Row>
                    <Col class="form-label label-border" span="4">贸易方式</Col>
                    <Col span="4">
                    <FormItem prop="tradeMode" class="formInput requireBG">
                        <Select v-model="form.tradeMode" class="small-select">
                            <Option
                                v-for="item in tradeModeList"
                                :value="item.id"
                                :key="item.id"
                            >{{item.id}}-{{item.name}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">进口国(地区)</Col>
                    <Col span="4">
                    <FormItem prop="importCountry" class="formInput requireBG">
                        <Select v-model="form.importCountry" class="small-select">
                            <Option
                                :value="item.dataCode"
                                v-for="item in countryRegionList"
                                :key="item.id"
                            >{{item.dataCode}}-{{item.dataName}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">运输方式</Col>
                    <Col span="4">
                    <FormItem prop="transport" class="formInput requireBG">
                        <Select v-model="form.transport" class="small-select">
                            <Option
                                :value="item.id"
                                v-for="item in transportList"
                                :key="item.id"
                            >{{item.id}}-{{item.name}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第6行 -->
                <Row>
                    <Col class="form-label label-border label-bottom" span="4">合同号</Col>
                    <Col span="4">
                    <FormItem prop="contractNo" class="formInput requireBG">
                        <Input v-model="form.contractNo" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="4">付款方式</Col>
                    <Col span="4">
                    <FormItem prop="payType" class="formInput requireBG">
                        <Select v-model="form.payType" class="small-select">
                            <Option
                                :value="item.id"
                                v-for="item in payTypeList"
                                :key="item.id"
                            >{{item.id}}-{{item.name}}</Option>
                        </Select>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft label-bottom" span="4">有效截至日期</Col>
                    <Col span="4">
                    <FormItem prop="expiryDate" class="formInput requireBG">
                        <Date-picker
                            @on-change="handleDateChange($event,'expiryDate')"
                            :value.sync="form.expiryDate"
                            type="date"
                            placeholder="YYYY-MM-DD"
                        ></Date-picker>
                    </FormItem>
                    </Col>
                </Row>

                <div class="base-info">
                    <h3>商品信息</h3>
                </div>

                <!-- 第1行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">商品代码</Col>
                    <Col span="4">
                    <FormItem prop="commodityCode" class="formInput requireBG">
                        <i-input icon="ios-search" @click.native="openModal" v-model="form.commodityCode" />

                    </FormItem>
                    </Col>
                    <Col class="form-label label-border label-top" span="4">商品名称</Col>
                    <Col span="4">
                    <FormItem prop="commodityName " class="formInput">
                        <Input disabled v-model="form.commodityName" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border label-top" span="4">商品单位</Col>
                    <Col span="4">
                    <FormItem prop="commodityUnit" class="formInput">
                        <Input disabled v-model="form.commodityUnit" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第2行 -->
                <Row>
                    <Col class="form-label label-border" span="4">单价币别</Col>
                    <Col span="4">
                    <FormItem prop="univalent" class="formInput requireBG">
                        <Input v-model="form.univalent" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">合计数量</Col>
                    <Col span="4">
                    <FormItem prop="num" class="formInput">
                        <Input disabled v-model="form.num" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border-noleft" span="4">总金额</Col>
                    <Col span="4">
                    <FormItem prop="amount " class="formInput">
                        <Input disabled v-model="form.amount" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第3行 -->
                <Row>
                    <Col class="form-label label-border" span="4">证明书编号</Col>
                    <Col span="4">
                    <FormItem prop="certificateNo " class="formInput requireBG">
                        <Input disabled v-model="form.certificateNo" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border" span="4">批复单号</Col>
                    <Col span="12">
                    <FormItem prop="replyNo" class="formInput requireBG">
                        <Input disabled v-model="form.replyNo" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第4行 -->
                <Row>
                    <Col class="form-label label-border" span="4">品牌</Col>
                    <Col span="4">
                    <FormItem prop="brand" class="formInput requireBG">
                        <Input disabled v-model="form.brand" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border" span="4">
                    <Button type="primary">点击查看品牌说明</Button>
                    </Col>
                    <Col class="form-label label-border" span="4"></Col>
                    <Col class="form-label label-border" span="4"></Col>
                    <Col class="form-label label-border" span="4"></Col>
                </Row>
                <!-- 第5行 -->
                <Row>
                    <Col class="form-label label-border label-bottom" span="4">设备状态</Col>
                    <Col span="4">
                    <FormItem
                        prop="equipmentStatus"
                        class="formInput requireBG label-bottom label-left m-1"
                    >
                        <Radio-group v-model="form.equipmentStatus">
                            <Radio :value="0" :label="0">新</Radio>
                            <Radio :value="1" :label="1">旧</Radio>
                        </Radio-group>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border label-bottom" span="4"></Col>
                    <Col class="form-label label-border label-bottom" span="4"></Col>
                    <Col class="form-label label-border label-bottom" span="4"></Col>
                    <Col class="form-label label-border label-bottom" span="4"></Col>
                </Row>

                <div class="btns-box mt10" v-if="form.list">
                    <Button type="primary" @click="saveGood">暂存</Button>
                    <Button @click="delGood">删除</Button>
                </div>
                <div class="mt10">
                    <Table
                        v-if="form.list"
                        border
                        :columns="columns"
                        @on-selection-change="getSectedGood"
                        :data="this.form.list"
                    >
                        <template slot-scope="{row, index }" slot="model">
                            <Input
                                :disabled="form.list&&form.list[index].status==1"
                                style="max-width:180px"
                                size="small"
                                v-model="form.list[index].model"
                            />
                        </template>
                        <template slot-scope="{row,index}" slot="price">
                            <inputNumber
                                :disabled="form.list&&form.list[index].status==1"
                                :min="0"
                                style="max-width:180px"
                                size="small"
                                v-model="form.list[index].price"
                            />
                        </template>
                        <template slot-scope="{row, index}" slot="num">
                            <inputNumber
                                :disabled="form.list&&form.list[index].status==1"
                                :min="0"
                                style="max-width:180px"
                                size="small"
                                v-model="form.list[index].num"
                            />
                        </template>
                        <template slot-scope="{row, index}" slot="totalPrice">
                            <inputNumber
                                :disabled="form.list&&form.list[index].status==1"
                                style="max-width:180px"
                                size="small"
                                v-model="form.list[index].totalPrice"
                            />
                        </template>
                        <template slot-scope="{ row,index }" slot="action">
                            <a @click="saveOne(index)">保存</a>
                        </template>
                    </Table>
                </div>
                <div class="base-info">
                    <h3>商品信息</h3>
                </div>

                <!-- 第1行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">备注</Col>
                    <Col span="20">
                    <FormItem prop="remark " class="formInput">
                        <Input v-model="form.remark" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第2行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">是否一批一证</Col>
                    <Col span="4">
                    <FormItem prop="oneCert" class="formInput requireBG label-left label-bottom m-1">
                        <Radio-group v-model="form.oneCert">
                            <Radio :value="0" :label="0">新</Radio>
                            <Radio :value="1" :label="1">旧</Radio>
                        </Radio-group>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border" span="4">发证机构</Col>
                    <Col span="12">
                    <FormItem prop="certAuthority " class="formInput">
                        <Input disabled v-model="form.certAuthority" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第3行 -->
                <Row>
                    <Col class="form-label label-border label-top label-left" span="4">是否延申打印</Col>
                    <Col span="4">
                    <FormItem prop="extendPrinting" class="formInput requireBG label-left label-bottom m-1">
                        <Radio-group v-model="form.extendPrinting">
                            <Radio :value="0" :label="0">新</Radio>
                            <Radio :value="1" :label="1">旧</Radio>
                        </Radio-group>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border " span="4">打印终端</Col>
                    <Col span="12">
                    <FormItem prop="printingTerminal " class="formInput">
                        <Input disabled v-model="form.printingTerminal" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第4行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">是否异地打证</Col>
                    <Col span="4">
                    <FormItem prop="otherPlace " class="formInput requireBG label-left label-bottom m-1">
                        <Radio-group v-model="form.otherPlace">
                            <Radio :value="0" :label="0">新</Radio>
                            <Radio :value="1" :label="1">旧</Radio>
                        </Radio-group>
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border label-top" span="4">异地打证机构</Col>
                    <Col span="12">
                    <FormItem prop="organization" class="formInput">
                        <Input disabled v-model="form.organization" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第5行 -->
                <Row>
                    <Col class="form-label label-border label-top" span="4">联系人</Col>
                    <Col span="4">
                    <FormItem prop="contacts" class="formInput requireBG">
                        <Input v-model="form.contacts" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border" span="4">联系电话</Col>
                    <Col span="4">
                    <FormItem prop="telephone" class="formInput requireBG">
                        <Input v-model="form.telephone" />
                    </FormItem>
                    </Col>
                    <Col class="form-label label-border" span="4">申请日期</Col>
                    <Col span="4">
                    <FormItem prop="applyDate " class="formInput">
                        <Input disabled v-model="form.applyDate" />
                    </FormItem>
                    </Col>
                </Row>
                <!-- 第6行 -->
                <Row>
                    <Col class="form-label label-border label-bottom" span="4">附加信息说明</Col>
                    <Col span="20">
                    <FormItem prop="additionalInfo " class="formInput">
                        <Input v-model="form.additionalInfo" />
                    </FormItem>
                    </Col>
                </Row>
            </Form>

        </div>
        <Modal
            title="添加试卷"
            :width="900"
            v-model="vs"
            @on-ok="ok"
            @on-cancel="cancel"
        >
            <div class="clearfix" >
                <Form class="f-fl" inline :label-width="150">
                    <FormItem label="商品代码">
                        <Input
                            v-model="params.code"
                            placeholder=""
                        ></Input>
                    </FormItem>
                    <FormItem label="商品名称">
                        <Input
                            v-model="params.name"
                            placeholder=""
                        ></Input>
                    </FormItem>
                    <Button type="primary" @click="queryList">搜索</Button>
                </Form>
            </div>
            <Table ref="ta" :data="qList" :columns="qColumns" highlight-row @on-current-change="changeSelect">
                <template slot="nd">
                    <span>2020</span>
                </template>
                <template slot="action">
                    <span> - </span>
                </template>
            </Table>
            <div class="content-footer">
                <Pagination
                    :pageSize.sync="params.pageSize"
                    :current.sync="params.pageNum"
                    :total="params.total"
                    @change="queryList"
                />

            </div>

        </Modal>
    </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import { queryTeacherList } from '@/api/userManage'
import { queryCode, licenceExportInfo, licenceExportSave, licenceExportDel } from '@/api/licence'
import $ from 'jquery'
import { getDicByKey } from '@/libs/getDicDataList'
export default {
    inject: ['nextPageReload'],
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    data () {
        return {
            qList: [],
            params: {
                code: '',
                name: '',
                pageNum: 1,
                pageSize: 10,
                total: 0
            },
            vs: false,
            now: {},
            goodStatus: 0,
            selected: [],
            btnDisabled: false,
            countryRegionList: [], // 进口国别
            customsCodeList: [], // 报关
            transportList: [
                { id: '1', name: '海上运输' },
                { id: '2', name: '铁路运输' },
                { id: '3', name: '公路运输' },
                { id: '4', name: '航空运输' },
                { id: '5', name: '邮政运输' },
                { id: '6', name: '海运陆运' },
                { id: '7', name: '固定运输' },
                { id: '8', name: '内河运输' },
                { id: '9', name: '海运空运' }
            ], // 运输方式
            payTypeList: [
                { id: '0', name: '信用证' },
                { id: '1', name: '托收' },
                { id: '2', name: '汇付' },
                { id: '3', name: '本票' },
                { id: '4', name: '现金' },
                { id: '5', name: '记账' },
                { id: '6', name: '免费' }
            ], // 付款方式
            columns: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '序号',
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '规格型号',
                    slot: 'model',
                    align: 'center'
                },
                {
                    title: '单价',
                    slot: 'price',
                    align: 'center'
                },
                {
                    title: '数量',
                    slot: 'num',
                    align: 'center'
                },
                {
                    title: '总价',
                    slot: 'totalPrice',
                    align: 'center'
                },
                {
                    title: '操作',
                    slot: 'action',
                    align: 'center'
                }
            ],
            qColumns: [
                {
                    title: '序号',
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '年度',
                    slot: 'nd',
                    align: 'center'
                },
                {
                    title: '进口商品代码',
                    key: 'codeTs',
                    align: 'center'
                },
                {
                    title: '商品名称',
                    key: 'goodsName',
                    align: 'center'
                },
                {
                    title: '计量单位',
                    key: 'unit',
                    align: 'center'
                },
                {
                    title: '商品目录',
                    slot: 'action',
                    align: 'center'
                }
            ],
            currentIndex: 0,
            cName: '', // 公司中文名称
            bit: '%',
            usd: 'USD',
            form: {
                practicalTrainingId: '', // 实训id
                applyId: '', // 申请编号
                commerceApplyId: '', // 商务部申请表号
                licenceKey: '', // 许可证号
                year: '', // 年度
                status: '', // 状态
                customsPort: '', // 报关口岸
                exporterCode: '', // 出口商代码
                exporterSocialCode: '', // 出口商社会信用代码
                exporterName: '', // 出口商名称
                shipperCode: '', // 发货人代码
                shipperSocialCode: '', // 发货人社会信用代码
                shipperName: '', // 发货人名称
                tradeMode: '', // 贸易方式
                importCountry: '', // 进口国(地区)
                transport: '', // 运输方式
                contractNo: '', // 合同号
                payType: '', // 付款方式
                expiryDate: '', // 有效截至日期
                commodityCode: '', // 商品代码
                commodityName: '', // 商品名称
                commodityUnit: '', // 商品单位
                univalent: '', // 单价币别
                num: '', // 合计数量
                amount: '', // 总金额
                certificateNo: '', // 证明书编号
                replyNo: '', // 批复单号
                brand: '', // 品牌
                equipmentStatus: null, // 设备状态
                list: [
                    {
                        id: 0,
                        model: '',
                        price: null,
                        num: null,
                        totalPrice: null,
                        status: 0
                    },
                    {
                        id: 1,
                        model: '',
                        price: null,
                        num: null,
                        totalPrice: null,
                        status: 0
                    },
                    {
                        id: 2,
                        model: '',
                        price: null,
                        num: null,
                        totalPrice: null,
                        status: 0
                    },
                    {
                        id: 3,
                        model: '',
                        price: null,
                        num: null,
                        totalPrice: null,
                        status: 0
                    }
                ],
                remark: '', // 备注
                oneCert: '', // 是否一批一证
                certAuthority: '', // 发证机构
                extendPrinting: '', // 是否延申打印
                printingTerminal: '', // 打印终端
                otherPlace: '', // 是否异地打证
                organization: '', // 异地打证机构
                contacts: '', // 联系人
                telephone: '', // 联系电话
                applyDate: '', // 申请日期
                additionalInfo: '' // 附加信息
            },
            formRules: {
                year: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                customsPort: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                shipperCode: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                shipperName: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                tradeMode: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                importCountry: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                transport: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                contractNo: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                payType: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                expiryDate: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                commodityCode: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                univalent: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                contacts: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ],
                telephone: [
                    {
                        required: true,
                        message: '',
                        trigger: 'change,blur'
                    }
                ]
            },
            rules: {
                // HS编码
                hsCode: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 非原产成分
                nonOriginalIngredients: [
                    {
                        type: 'number',
                        required: true,
                        message: '',
                        trigger: 'blur,change'
                    }
                ],
                // 中文名称
                chineseName: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 英文名称
                englishName: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 数量
                goodsQuantity: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 英文
                goodsUnitE: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 中文
                goodsUnit: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // fbo发票金额
                invoiceAmount: [
                    {
                        type: 'number',
                        required: true,
                        message: '',
                        trigger: 'blur,change'
                    }
                ],
                // 生产商代码
                manufacturerCode: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // FOB值（美元）
                fob: [
                    {
                        type: 'number',
                        required: true,
                        message: '',
                        trigger: 'blur,change'
                    }
                ],
                // 货物描述
                goodsDesc: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 生产商名称
                manufacturerName: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ],
                // 联系人
                contacts: [
                    {
                        required: true,
                        message: '',
                        trigger: 'blur'
                    }
                ]
            },
            tips: {
                feeRate: ''
            },
            tradeModeList: [
                { id: '10', name: '一般贸易' },
                { id: '11', name: '易货贸易' },
                { id: '12', name: '补偿贸易' },
                { id: '13', name: '协定贸易' },
                { id: '14', name: '进料加工' },
                { id: '15', name: '来料加工' },
                { id: '16', name: '出料加工' },
                { id: '17', name: '寄售贸易' },
                { id: '18', name: '国际租赁' },
                { id: '19', name: '边境贸易' },
                { id: '20', name: '转口贸易' },
                { id: '21', name: '许可贸易' },
                { id: '22', name: '期货贸易' },
                { id: '23', name: '承包工程' },
                { id: '24', name: '国际招标' },
                { id: '25', name: '国际展览' },
                { id: '26', name: '国际拍卖' },
                { id: '27', name: '国际贷款进口' },
                { id: '28', name: '归还贷款出口' },
                { id: '29', name: '外资企业进口' }
            ],
            originStandardList: [
                { id: 'F', name: 'F' },
                { id: 'P', name: 'P' },
                { id: 'PK', name: 'PK' },
                { id: 'W', name: 'W' },
                { id: 'Y', name: 'Y' }
            ]
        }
    },
    computed: {
        ...mapState({
            isTeacher: (state) => state.user.roleType === '3',
            userId: (state) => state.user.userId
        })
    },
    mounted () {
        let applyId = this.$route.query.applyId
        if (applyId) {
            licenceExportInfo(applyId).then((res) => {
                this.form = Object.assign(this.form, res.data.data.emtLicenceExport)
                this.form.list = res.data.data.list
            })
        } else {
            this.getAdd()
        }
        let that = this
        let h = $
        if (this.$el) {
            $(this.$el).on('keyup', 'input', function (e) {
                if (e.keyCode == 13) {
                    var index = h('input:text').index(h(e.target))
                    console.log(index)
                    that.getInput(index)
                }
            })
        }
        this.getCountryRegionList()
        this.getCustomsCodeList()
    },
    methods: {
        ...mapMutations(['removeTagNav']),
        // 贸易国
        getCountryRegionList () {
            return getDicByKey('COUNTRY_REGION').then((list) => {
                this.countryRegionList = Object.freeze(list)
            })
        },
        // 报关区域
        getCustomsCodeList () {
            return getDicByKey('CUSTOMS_CODE').then((list) => {
                this.customsCodeList = Object.freeze(list)
            })
        },
        changeSelect (data) {
            this.now = data
            console.log(data)
        },
        saveOne (index) {
            console.log(index)
            this.form.list[index].status = 1
        },
        queryList () {
            queryCode({
                name: this.params.name,
                code: this.params.code,
                pageSize: this.params.pageSize,
                pageNum: this.params.pageNum
            }).then(res => {
                this.qList = res.data.data.list
                this.params.total = res.data.data.total
            })
        },
        openModal () {
            this.vs = true
            this.queryList()
        },
        ok () {
            this.form.commodityCode = this.now.codeTs
            this.form.commodityName = this.now.goodsName
            this.form.commodityUnit = this.now.unit
        },
        cancel () {

        },
        getInput (index) {
            var h = $
            h('input:text')[index + 1].focus()
        },
        handleDateChange (v, key) {
            this.form[key] = v
        },
        getAdd () {

        },
        saveAdd () {
            this.form.status = 0
            licenceExportSave(this.form).then((res) => {
                if (res.data.code != '0000') {
                    this.$Message.error(res.data.data)
                    return
                }
                this.$Message.success('成功')
                this.nextPageReload()
                this.$router.push({
                    name: 'licenceExport'
                })
            })
        },
        queryTeaList () {
            return queryTeacherList({
                pageNum: 1,
                pageSize: 9999
            }).then((res) => {
                if (res.data.code === '0000') {
                    const data = res.data.data
                    this.teaList = Object.freeze(
                        data.list.map((item) => ({
                            value: item.userId,
                            label: item.realName
                        }))
                    )
                }
            })
        },
        handleCancel () {
            this.removeTagNav(this.$route)
            this.$router.replace({
                name: 'classManageList'
            })
        },
        clearAll () {
            this.nextPageReload()
            this.$router.push({
                name: 'certAdd'
            })
        },
        submitAll () {
            this.$refs.form.validate((v) => {
                if (v) {
                    this.form.status = 1 // 申报
                    licenceExportSave(this.form).then((res) => {
                        if (res.data.code != '0000') {
                            this.$Message.error(res.data.msg)
                            return
                        }
                        this.$Message.success('成功')
                        this.nextPageReload()
                        this.$router.push({
                            name: 'licenceExport'
                        })
                    })
                }
            })
        },
        makeFileAll () {},
        delAll () {
            licenceExportDel({ ids: this.form.id }).then((res) => {
                if (res.data.code === '0000') {
                    this.$Message.success('删除成功')
                    this.nextPageReload()
                    this.$router.push({
                        name: 'licenceExport'
                    })
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        saveGood () {
            this.form.list.map((item) => {
                item.status = 1
            })
        },
        delGood () {
            // 先删除
            this.selected.map((item, index) => {
                this.form.list[item.id].model = ''
                this.form.list[item.id].price = null
                this.form.list[item.id].num = null
                this.form.list[item.id].totalPrice = null
            })
        },
        sendToSingleWindow () {},
        getSectedGood (data) {
            console.log(data)
            this.selected = data
        },
        changeNow (data) {}
    }
}
</script>
<style lang="less">
.small-select {
  height: 20px;
  line-height: 20px;
  .ivu-select-selection {
    height: 20px;
    line-height: 20px;
    border-radius: 0px;
  }
  .ivu-select-single .ivu-select-selection .ivu-select-placeholder,
  .ivu-select-single .ivu-select-selection .ivu-select-selected-value {
    height: 20px;
    line-height: 20px;
  }
}
.h63 {
  height: 63px;
  line-height: 63px;
  textarea {
    height: 63px !important;
  }
}
.h70 {
  textarea {
    height: 76px !important;
  }
}
</style>
<style lang="less" scoped>
.h63 {
  height: 63px;
  line-height: 63px;
  .ivu-input {
    height: 63px;
  }
}
.label-bottom {
  border-bottom: 1px solid #b7b7b7;
}
.label-left {
  border-left: 1px solid #b7b7b7;
}
.m-1 {
  margin-top: -2px !important;
}
.label-top {
  border-top: 1px solid #b7b7b7;
}
.label-border {
  border-top: 1px solid #b7b7b7;
  border-left: 1px solid #b7b7b7;
}
.label-border-noleft {
  border-top: 1px solid #b7b7b7;
}
.btns-box {
  .ivu-btn {
    font-size: 12px;
    height: 24px;
    line-height: 12px;
    padding: 3px 14px;
    font-family: "Microsoft YaHei";
    border-radius: 2px;
  }
  button {
    margin-right: 1px;
    margin-bottom: 1px;
  }
}
.content-body {
  margin-top: 8px;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.formInput {
  textarea {
    width: 100%;
    height: 63px;
    border-color: #b7b7b7;
  }
  select {
    height: 20px;
    line-height: 20px;
  }
}
.base-info {
  margin-top: 10px;
  h3 {
    color: #1291cc;
    font-size: 13px;
  }
}
.h70 {
  height: 76px;
  line-height: 76px;
  textarea {
    height: 76px;
  }
}
.mt10 {
  margin-top: 10px;
}
</style>
